package cn.main.entity.sys;

import cn.main.service.SysService;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import java.util.jar.Attributes;

/**
 * Author: chengwei
 * Date:   2016/7/12
 * Time:   16:45
 */
@Entity
@Table(name = "sys_role")
public class Role implements Serializable {
    private static final long serialVersionUID = -9017296855241160115L;
    @Id
    @Column(name = "role_id")
    private String roleId;
    
    @Column(name = "name")
    private String name;
    
    
    //子角色
    @OneToMany
    @JoinColumn(name = "parent_role_id")
    private Set<Role> roles;
    
    //角色权限
    @ManyToMany
    @JoinTable(name = "sys_authority_role",inverseJoinColumns ={@JoinColumn(name = "authority_id")},joinColumns = {@JoinColumn(name = "role_id")})
    private Set<Authority> authorities;
    
    //角色构架
    @ManyToMany
    @JoinTable(name = "sys_function_role",inverseJoinColumns ={@JoinColumn(name = "function_id")},joinColumns = {@JoinColumn(name = "role_id")})
    @JoinColumn(columnDefinition = "")
    private Set<SysFunction> functions;

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public Set<Role> getRoles() {
        return roles;
    }
    
    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    public Set<Authority> getAuthorities() {
        return authorities;
    }

    public void setAuthorities(Set<Authority> authorities) {
        this.authorities = authorities;
    }

    public Set<SysFunction> getFunctions() {
        return functions;
    }

    public void setFunctions(Set<SysFunction> functions) {
        this.functions = functions;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Role role = (Role) o;

        return !(getRoleId() != null ? !getRoleId().equals(role.getRoleId()) : role.getRoleId() != null);

    }

    @Override
    public int hashCode() {
        return getRoleId() != null ? getRoleId().hashCode() : 0;
    }
}
